/*
 * @Date: 2022-05-07 11:18:11
 * @LastEditors: 春贰
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2022-10-11 09:25:41
 * @FilePath: \server\app\task\task.go
 */
package task

import (
	"fmt"
	"go2admin_pure/system/core/log"
	"time"
)

func Init() {
	//避免影响主程序
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("task发生错误", err)
		}
	}()

	go dotesk("工单执行", 200, func() {

	})

}

type tastfunc func() //定义一个函数类型
func dotesk(name string, timesecond int64, f tastfunc) {
	//避免影响主程序
	defer func() {
		if err := recover(); err != nil {
			log.Write(log.Error, name+"发生错误")
			fmt.Println(name+"发生错误", err)
		}
	}() //捕获错误

	for {
		//执行任务
		f()
		time.Sleep(time.Duration(timesecond) * time.Second)
	}
}
